#include "client.h"

int recvn(int sockfd,void *buf, int n){
    // void *的指针不能解引用，也不能偏移
    char *p = (char *)buf;
    while(cursize < n){
//        sleep(1);
        ssize_t sret = recv(sockfd,p+cursize,n-cursize,0);
//        printf("sret = %ld\n",sret);
        if(sret <= 0){
            printf("发送放异常断开!\n");
            kill(pid,sig);
            sleep(1);
        }
        cursize += sret;
        printf("正在下载... %5.2lf%%\r",(offset+cursize)*100.0/filesize);
        fflush(stdout);
    }
    printf("100.00%%\n");
    return 0;
}
